﻿package dk.gaming.rummikub.primitive
{
	import flash.display.MovieClip;
	
	public class RackLine extends MovieClip
	{
		
		private var slots : Array;
		
		private var type : RackLineType;
		
		public function RackLine($type:RackLineType)
		{
			slots = new Array();
			
			for(var i : Number = 0; i<13; i++)
			{
				var slot : Slot = new Slot(i+1);
				
				slot.x = i * slot.width;
				
				slots.push(slot);
			}
			
		}
		
		public function get Type():RackLineType
		{
			return type;
		}
		
		public function get Slots():Array
		{
			return slots;
		}
		
		public function GetAttempts():Array
		{
			var attemptsarray : Array = new Array();
			
			var attemptnum : Number = 0;
			
			attemptsarray[attemptnum] = new Array();
			
			for(var i : Number = 0; i<slots.length; i++)
			{
				if( (slots[i] as Slot).Filled )
				{
					(attemptsarray[attemptnum] as Array).push(slots[i]);
				}
				else if( !(slots[i] as Slot).Filled )
				{
					attemptnum++;
					attemptsarray[attemptnum] = new Array();
				}
			}
			
			var filteredattempts : Array = new Array();
			
			for(var j : Number = 0; j<attemptsarray.length; j++)
			{
				if( (attemptsarray[j] as Array).length > 2 )
				{
					filteredattempts.push(attemptsarray[j]);
				}
			}
			
			return filteredattempts;
			
		}
		
		
		
		
		
	}
	
	
	
	
}